#include <iostream>
using namespace std;

#include "easylogging++.h"
#include "easylogginghelper.h"

void ReadTxtData(LogConfig& conf);

int main(int argc, char** argv)
{
    //Easylogging++使用参考https://www.yuque.com/lengyuezuixue/kggswo/rch2uo
    // 定义日志配置项
    LogConfig conf = {
        .logRootPath  = "D:\\Log",
        .remain_days = 3,
        .type = 1,
    };

    /// 防止Fatal级别日志中断程序
    el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
    /// 选择划分级别的日志
    el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);

    //   enum class Level : base::type::EnumType {
    //      Global = 1,
    //      Trace = 2,
    //      Debug = 4,
    //      Fatal = 8,
    //      Error = 16,
    //      Warning = 32,
    //      Verbose = 64,
    //      Info = 128,
    //      Unknown = 1010
    //   };
    /// 设置级别门阀值，修改参数可以控制日志输出
    el::Loggers::setLoggingLevel(el::Level::Global);

    el::InitEasylogging(conf);

    for (size_t i = 0; i < 2; i++)
    {
        LOG(TRACE) << "***** trace log  *****" << i;
        LOG(DEBUG) << "***** debug log  *****" << i;
        LOG(ERROR) << "***** error log  *****" << i;
        LOG(WARNING) << "***** warning log  *****" << i;
        LOG(INFO) << "***** info log  *****" << i;
        //不要轻易使用，程序会退出
        //LOG(FATAL) << "***** fatal log  *****" << i;
        Sleep(100);
    }

    cout << conf.filePath << endl;
    cout << conf.fileName << endl;
    ReadTxtData(conf);
    while(1){ Sleep(1000);}
    return 0;
}

void ReadTxtData(LogConfig& conf)
{
    ifstream fin;
    conf.fileName = "20230220_TRACE.log";

    string str = conf.filePath + conf.fileName;
    printf("0---%s\n", str.c_str());
    fin.open(str.c_str(), ios::in);
    if (!fin.is_open())
    {
        cout << "无法找到这个文件！" << endl;
        return;
    }
    string buff;
    while (getline(fin, buff))
    {
        cout << buff<<endl;
    }
    fin.close();
}
